package com.zzyl.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.zzyl.base.PageResponse;
import com.zzyl.dto.NursingLevelDto;
import com.zzyl.entity.NursingLevel;
import com.zzyl.entity.NursingPlan;
import com.zzyl.mapper.NursingLevelMapper;
import com.zzyl.service.NursingLevelService;
import com.zzyl.vo.NursingLevelVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class NursingLevelServiceImpl implements NursingLevelService {
    @Autowired
    private NursingLevelMapper nursingLevelMapper;

    @Override
    public PageResponse<NursingLevelVo> pageNursingLevel(Integer pageNum, Integer pageSize, String name, Integer status) {
        PageHelper.startPage(pageNum, pageSize);
        Page<NursingLevel> nursingLevelServicePage = nursingLevelMapper.pageNursingLevel(name, status);
        return PageResponse.of(nursingLevelServicePage, NursingLevelVo.class);
    }

    @Override
    public void addNursingLevel(NursingLevelDto nursingLevelDto) {
        nursingLevelMapper.addNursingLevel(BeanUtil.toBean(nursingLevelDto, NursingLevel.class));
    }

    @Override
    public NursingLevelVo getNursingLevelById(Integer id) {
        NursingLevel nursingPlan = nursingLevelMapper.getNursingLevelById(id);
        return BeanUtil.toBean(nursingPlan, NursingLevelVo.class);
    }

    @Override
    public void updateNursingLevel(NursingLevelDto nursingLevelDto) {
        nursingLevelMapper.updateNursingLevel(BeanUtil.toBean(nursingLevelDto, NursingLevel.class));
    }

    @Override
    public void deleteNursingLevel(Integer id) {
        nursingLevelMapper.deleteNursingLevelById(id);
    }

    @Override
    public void forbiddenNursingLevel(Integer id, Integer status) {
        NursingLevel nursingLevel = new NursingLevel();
        nursingLevel.setId(Long.valueOf(id));
        nursingLevel.setStatus(status);
        nursingLevelMapper.updateNursingLevel(nursingLevel);
    }

    @Override
    public List<NursingLevelVo> getAllNursingLevel() {

        List<NursingLevel> nursingLevels = nursingLevelMapper.getAllNursingLevel();
        return BeanUtil.copyToList(nursingLevels, NursingLevelVo.class);
    }
}
